function previewImage(obj, num) {
    fileObj = document.getElementById('file' + num);
    value = window.URL.createObjectURL(fileObj.files[0]);
    $("#img_show").attr('src', value);
}

function previewImages(obj, num) {
    $('.delBtn').attr('style','display:-webkit-inline-box;float: right;');
    fileObj = document.getElementById('file' + num);
    value = window.URL.createObjectURL(fileObj.files[0]);
    var img = $("#img_show");
    img.attr('src', value);
    img.attr('style', 'display:-webkit-inline-box;margin:0 20px 0 0;width: 60px;height: 60px;border-radius: 50%;');
    var formData = new FormData();
    formData.append('_token', $('meta[name="csrf-token"]').attr('content'));
    formData.append('file', obj.files[0]);
    formData.append('get', 'file');
    formData.append('user', 'blog');
    formData.append('category', 'link');
    formData.append('post', 'link');
    $.ajax({
        type: 'POST',
        url: '/upload',
        data: formData,
        mimeType: "multipart/form-data",
        contentType: false, //必须false才会自动加上正确的Content-Type
        processData: false, //必须false才会避开jQuery对 formdata 的默认处理
        dataType: "json",
        beforeSend: function () {
            layer.load(1, {
                shade: [0.1, '#333333'] //0.1透明度的白色背景
            });
        },
        complete: function (XHR) {
            XHR = null;
        },
        error: function (xhr) {//获取ajax的错误信息
            layer.alert(xhr.responseText, "Failed",function () {
                layer.closeAll();
            });
        },
        success: function (res) {
            layer.closeAll();
            if (res.code == 403) {
                layer.msg(res.msg, {icon: 4, time: 3000})
                return false;
            }
            if (res.code != 200) {
                layer.msg(res.msg, {icon: 5, time: 3000})
                return false;
            }
            layer.msg(res.msg, {icon: 1, time: 3000}, function () {
                $("#pic").val(res.data.id);
            });
        }
    })
}
